package controllers

import (
	"runtime"
	"strings"
)

func ReplyData(data any) map[string]any {
	return map[string]any{
		"cmd":     GetFunc(2),
		"message": "ok",
		"code":    200,
		"data":    data,
	}
}

func ReplyError(tip string) map[string]any {
	return map[string]any{
		"cmd":     GetFunc(2),
		"message": tip,
		"code":    202,
	}
}

func ReplyPanic(cmd string, tip string) map[string]any {
	return map[string]any{
		"cmd":     cmd,
		"message": tip,
		"code":    202,
	}
}

func ReplyOk() map[string]any {
	return map[string]any{
		"cmd":     GetFunc(2),
		"message": "ok",
		"code":    200,
	}
}

func GetFunc(skip int) string {
	pc, _, _, ok := runtime.Caller(skip)
	var fun string
	if !ok {
		fun = "-"
	} else {
		fun = runtime.FuncForPC(pc).Name()
		ss := strings.Split(fun, ".")
		fun = strings.ToLower(ss[len(ss)-1])
	}
	return fun
}

//func (c *beego.Controller) Set() {
//
//}
